﻿using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using pttk_htt_hr.DAO;
using pttk_htt_hr.DTO;

namespace pttk_htt_hr.DAO
{
    class ThucDonTuanToiBUS
    {
        #region Select
        /// <summary>
        /// Lay_ThucDonTuanToi
        /// </summary>
        /// <param name="PLTDTTparams"></param>
        /// <param name="CTPLTDTTparams"></param>
        /// <returns>ThucDonTuanToiDTO</returns>
        public static ThucDonTuanToiDTO Lay_ThucDonTuanToi(List<SqlParameter> PLTDTTparams, List<SqlParameter> CTPLTDTTparams)
        {
            return ThucDonTuanToiDAO.Lay_ThucDonTuanToi(PLTDTTparams, CTPLTDTTparams);
        }

        #endregion

        #region Insert
        /// <summary>
        /// Them_ThucDonTuanToi
        /// </summary>
        /// <param name="PLTDTTparams"></param>
        /// <param name="CTPLTDTTparams"></param>
        /// <param name="Deleteparams"></param>
        /// <returns>int</returns>
        public static int Them_ThucDonTuanToi(List<SqlParameter> PLTDTTparams, List<List<SqlParameter>> CTPLTDTTparams, List<SqlParameter> Deleteparams)
        {
            int k = 0;
            try
            {
                k = ThucDonTuanToiDAO.Them_ThucDonTuanToi(PLTDTTparams, CTPLTDTTparams, Deleteparams);
            }
            catch
            {
                return 0;
            }
            if (k > 0)
                return 1;
            return 0;
        }
        #endregion


        #region Update
        public static int CapNhat_ThucDonTuanToi(List<List<SqlParameter>> CTPLTDTTparams, List<SqlParameter> PLTDTTparams, string ParentID, string[] MainKeys)
        {
            int spRes = -1;
            int spRes1 = ChiTietPhieuLapThucDonTuanToiBUS.CapNhat_ChiTietPhieuLapThucDonToi(CTPLTDTTparams,ParentID,MainKeys);
            int sqRes2 = PhieuLapThucDonTuanToiBUS.CapNhat_PhieuLapThucDonToi(PLTDTTparams);

            if (spRes1 == 0 && spRes1 == 0)
            {
                spRes = 0;
            }

            return spRes;
        }
        #endregion


        #region Delete
        /// <summary>
        /// Mục đích: Xóa 1 danh sách thực đơn
        /// </summary>
        /// <param name="parameters"></param>
        /// <returns></returns>
        public static int Delete_ThucDonTuanToi(List<SqlParameter> CTPLTDTTparams, List<SqlParameter> PLTDTTparams)
        {
            int spRes = -1;
            int spRes1 = ChiTietPhieuLapThucDonTuanToiBUS.Delete_ChiTietPhieuLapThucDonToi(CTPLTDTTparams);
            int sqRes2 = PhieuLapThucDonTuanToiBUS.Delete_PhieuLapThucDonToi(PLTDTTparams);

            if (spRes1 == 0 && spRes1 == 0)
            {
                spRes = 0;
            }

            return spRes;
        }

        public static int DeleteAll_ThucDonTuanToi(List<List<SqlParameter>> PLTDTTparams, List<List<SqlParameter>> CTPLTDTTparams)
        {
            return ThucDonTuanToiDAO.DeleteAll_ThucDonTuanToi(PLTDTTparams, CTPLTDTTparams);
        }
        #endregion


        #region Other
        
        /// <summary>
        /// GetNextMaPLTDTT
        /// </summary>
        /// <returns>int = current index</returns>
        public static int GetNextMaPLTDTT()
        {
            return ThucDonTuanToiDAO.GetNextMaPLTDTT();
        }
        #endregion

    }
}